﻿using AutoMapper;
using Guoc.BigMall.Domain.Entity;
using Guoc.BigMall.WebService.Dto;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Guoc.BigMall.WebService.MapConfig
{
    public class AutoMapConfig
    {
        public static void RegisterAll()
        {
            Mapper.Initialize(cfg =>
            {
                AllMapppingConfig(cfg);
            });
        }

        private static void AllMapppingConfig(IMapperConfigurationExpression cfg)
        {
            cfg.CreateMap<SaleOrderCreateDto, SaleOrder>()
                .ForMember(dest => dest.Id, opt => opt.MapFrom(s => s.OrderId))
                .ForMember(dest => dest.Items, opt => opt.Ignore())
               .ReverseMap();

            cfg.CreateMap<SaleOrderItemDto, SaleOrderItem>()
              // .Ignore(m => m.Id)
              .ReverseMap();
            cfg.CreateMap<MemberAddressDto, MemberAddress>()
               .ForMember(dest => dest.AreaId, opt => opt.MapFrom(s => s.AreaCode))
               .ForMember(dest => dest.Address, opt => opt.MapFrom(s => s.AddressDetail))
               .ReverseMap();
        }
    }
}
